package com.zhuozhou.jdyc.main.goods.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseRecyclerViewFragment;
import com.zhuozhou.jdyc.base.BaseRecyclerViewModel;
import com.zhuozhou.jdyc.databinding.SmartrecyclerviewBinding;
import com.zhuozhou.jdyc.main.goods.activity.GoodsDetailActivity;
import com.zhuozhou.jdyc.main.goods.adapter.PickUpAdapter;
import com.zhuozhou.jdyc.main.goods.bean.TiHuoBase;

import static com.zhuozhou.jdyc.main.goods.activity.GoodsDetailActivity.PICKUP;

/**
 * Create by CherishTang on 2020/3/20 0020
 * describe:
 */
public class PickUpFragment extends BaseRecyclerViewFragment<BaseRecyclerViewModel, SmartrecyclerviewBinding, TiHuoBase> {

    private String commodity_id;

    @Override
    protected BaseRecyclerViewAdapter<TiHuoBase, ?> getRecyclerAdapter() {
        return new PickUpAdapter(getActivity());
    }

    @Override
    protected void initData(Bundle bundle) {
        super.initData(bundle);
        commodity_id = bundle.getString("commodity_id");
        requestData();
    }

    @Override
    protected void requestData() {
        super.requestData();
        mViewModel.getTiHuo(commodity_id, mCurrentPage);
    }

    public static Fragment instantiate(Bundle bundle) {
        Fragment fragment = new PickUpFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onItemClick(View view, int position) {
        super.onItemClick(view, position);
        Intent in = new Intent(getActivity(), GoodsDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("data", adapter.getList().get(position));
        in.putExtras(bundle);
        getActivity().setResult(PICKUP, in);
        getActivity().finish();
    }
}
